<?php
error_reporting(0);
/**
 * GameController
 * 
 * @author
 * @version 
 */
require_once 'Zend/Controller/Action.php';
class IndexController extends Sunnet_Controller_Action
{
	var $_arrParam;
    protected $domain = DOMAIN;
	public function init()
    {
        //      Truyền các tham số nhận được ra view
        $this->_arrParam = $this->_request->getParams();
        if (empty($this->_arrParam['page'])) {
            $this->_arrParam['page'] = 1;
        }
        if (empty($this->_arrParam['line_per_page'])) {
            $this->_arrParam['line_per_page'] = 10;
        }

        $this->view->arrParam = $this->_arrParam;
        $this->view->domain = $this->domain;
        $this->view->function = $this;
    }

    public function preDispatch(){
		$template_path = TEMPLATE_PATH . "/wap/default/";
		$this->loadTemplate($template_path,'template.ini','template');

        
    }

    public function indexAction (){       
//      Load js và css
        $this->view->headLink()->appendStylesheet('/css/style.css','screen');
        
        //load page 
        
    }
	
    //code date time
    public function convertTimeAgo ($activity_time){       
       $timeinsecond = time() - $activity_time;
       if($timeinsecond >=0){
         $minus  = abs(floor(($timeinsecond%3600)/60));
         $hour   =   abs(round(($timeinsecond-$minus*60)/3600,0));              
          
         $timematch = 0;
         if($timeinsecond<60){
            $timematch = $timeinsecond." giây trước";  
            return $timematch;
         }elseif(60<$timeinsecond && $timeinsecond<3600){
            $timematch = $minus." phút trước";      
            return $timematch;       
         }elseif(3600<=$timeinsecond && $timeinsecond<86400){
            $timematch = $hour." giờ trước"; 
            return $timematch;
         }elseif(86400<=$timeinsecond && $timeinsecond<518400){
            $timematch =  abs(round(($hour/24))) . " ngày trước";
            return $timematch;
         }else {
            $timematch= date('d/m/Y', $activity_time);
            return $timematch;
         }
         return $timematch;
       }
    }
    function cut_substr($str,$n)
    {       
        $str = strip_tags($str);   
        $str = trim($str);    
       // ----- remove control characters ----- 

        $str = str_replace("\r", '<br/>', $str);    // --- replace with empty space
        $str = str_replace("\n", '', $str);   // --- replace with space
        $str = str_replace("\t", '', $str);   // --- replace with space
        // ----- remove cac br lien tiep ----- 
        $str = preg_replace('#(<br */?>\s*)+#i', '<br />', $str);

        $html = substr($str,0,$n);
        $html = substr($html,0,strrpos($html,' '));

        return $html.'...';
    }  

    function cut_substr_strip($str)
    {                   
        $str = strip_tags($str);   
        $str = trim($str);    
       // ----- remove control characters ----- 

        $str = str_replace("\r", '<br/>', $str);    // --- replace with empty space
        $str = str_replace("\n", '', $str);   // --- replace with space
        $str = str_replace("\t", '', $str);   // --- replace with space
        // ----- remove cac br lien tiep ----- 
        $str = preg_replace('#(<br */?>\s*)+#i', '<br />', $str);

        return $str;

    }  

    public function getNganHangByID ($id){
        Zend_Loader::loadClass('Verify_Models_TblBankModel');
                $nganHang_model= new Verify_Models_TblBankModel();
                $nganhang = $nganHang_model->getIDNganHang($id);
        return $nganhang;
    }

}
